#!/bin/bash
# 执行：sh git_url_to_gitlab_api_url.sh http://aaa.gitlab.com/feg/fea-testing.git
# 结果：http://aaa.gitlab.com/api/v4/projects/feg%2Ffea-testing
cd `dirname "$0"`

if [ $# -ne 1 ] ;then
  echo "本脚本用于将http的git地址转换为取项目id的gitlab的api地址"
  echo "使用sh git_url_to_gitlab_api_url.sh 某某.git"
  exit
fi

gitlab_git_real_address=$1

gitlab_com_url=`echo $gitlab_git_real_address | cut -d/ -f3`
project_path=`echo $gitlab_git_real_address | cut -d/ -f4`
gitlab_project_name=`echo $gitlab_git_real_address | cut -d/ -f5 | cut -d. -f1`

echo http://$gitlab_com_url/api/v4/projects/$project_path%2F$gitlab_project_name

